﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WorldRacing2
{
    public abstract partial class ConfigurationDialog : Form
    {
        private Dictionary<string, UserControl> tabPages;
        private UserControl currentControl;

        public ConfigurationDialog()
        {
            InitializeComponent();
            this.tabPages = new Dictionary<string, UserControl>();
        }

        public void AddControl(string Name, UserControl control)
        {
            this.tabPages.Add(Name, control);
            control.Dock = DockStyle.Fill;

            Button button = new Button()
            {
                Name = Name,
                Text = Name,
                FlatStyle = FlatStyle.Flat,
                Dock = DockStyle.Top
            };
            button.Click += Button_Click;

            this.tableLayoutPanel_ButtonsLeft.Controls.Add(button, 0, this.tableLayoutPanel_ButtonsLeft.RowStyles.Count - 1);
            this.tableLayoutPanel_ButtonsLeft.RowStyles.Insert(0, new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F));
        }

        private void Button_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            UserControl control;
            if (this.tabPages.TryGetValue(button.Text, out control))
            {
                // Remove old page
                this.tableLayoutPanel_Main.Controls.Remove(this.currentControl);

                this.tableLayoutPanel_Main.Controls.Add(control, 1, 0);
                this.currentControl = control;
            }
        }
    }
}